#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt

class Display(object):
    def __init__(self):
        self.fig = plt.figure()


    def draw(self, sub_img, img_name, dl, dl_names):
        """
        Draw a curve chart at target sub-image.
        Args:
            sub_img : target sub-image for drawing. i.e: 221,222,223.224
            img_name: name for sub-name.
            dl : data list, i.e: [rs,ms,es].
                rs : list for real data.
                ms : list for measure data.
                es : list for estimate data.
            dl_names: name list for data. i.e: [name1,name2,name3]
        TODO:
            Add name for sub-image.
        """
        rs,ms,es = dl[0],dl[1],dl[2]
        rsn,msn,esn = dl_names[0],dl_names[1],dl_names[2]
        x = range(0,max(len(rs),len(ms),len(es)))
        # Draw
        plt.subplot(sub_img)
        self.__drawSingleCurve(x,rs,"k",rsn)
        self.__drawSingleCurve(x,ms,"ro",msn)
        self.__drawSingleCurve(x,es,"b--",esn)


    def show(self):
        plt.show()


    def __drawSingleCurve(self,x,y,style,name):
        """
        Drawing a single curve.
        TODO:
            Add name for curve.
        """
        if y==[]: return
        plt.plot(x,y,style)